<template>
  <div class="app-container">
  <div class="app-containermain">
  <div class="fontsize" style="margin-top: 30px;">企业微信配置</div>
    <el-form ref="dataForm" :rules="rules" :model="dataForm" status-icon label-position="left" label-width="100px" style="width: 100%;">
      <p class="fontsize">公司配置</p>

      <div class="flexdiv" prop="fsiteNo">
          <div class="fontw">*企业ID</div>
          <div><el-input readonly unselectable="on" v-model="dataForm.fsiteNo" style="width: 500px!important;" required="true"/></div>
      </div>
      <!-- <el-form-item label="*appid" prop="appid" style="width: 100%;color: red;">
        <el-input v-model="dataForm.appid" style="width: 300px!important;" />
      </el-form-item> -->
      <p class="fontsize">应用配置</p>
      <p class="fontsize">通讯录</p>
      <div class="flexdiv" prop="addressBookAppid">
          <!-- <div class="fontw">*Secret</div> -->
          <!-- <div class="fontw">*addressBookAppid</div> -->
          <div class="fontw">通讯录应用Appid</div>
          <!-- <div><el-input v-model="dataForm.secret" style="width: 500px!important;" /></div> -->
          <div><el-input v-model="dataForm.addressBookAppid" style="width: 500px!important;" margin-left="30px" /></div>
      </div>
      <div class="flexdiv" prop="addressBookSecret">
          <!-- <div class="fontw">*addressBookSecret</div> -->
          <div class="fontw">通讯录应用Secret</div>
          <div><el-input v-model="dataForm.addressBookSecret" style="width: 500px!important;" /></div>
      </div>

      <div class="flexdiv" prop="selfAppAgentid">
          <div class="fontw">自建应用Agentld</div>
          <div><el-input v-model="dataForm.selfAppAgentid" style="width: 500px!important;" /></div>
      </div>
      
      <!-- <el-form-item label="secret" prop="secret">
        <el-input v-model="dataForm.secret"  auto-complete="off"/>
      </el-form-item> -->
      <p class="fontsize">自建应用</p>

      <div class="flexdiv" prop="selfAppAppid">
          <div class="fontw">自建应用Appid</div>
          <div><el-input v-model="dataForm.selfAppAppid" style="width: 500px!important;" /></div>
      </div>
      <div class="flexdiv" prop="selfAppSecret">
          <div class="fontw">自建应用Secret</div>
          <div><el-input v-model="dataForm.selfAppSecret" style="width: 500px!important;" /></div>
      </div>
      
      <!-- <el-form-item label="appids" prop="appids">
        <el-input v-model="dataForm.appids"  auto-complete="off"/>
      </el-form-item> -->
    </el-form>
    <div style="text-align: center;margin-top:50px;">
      <el-button style="width: 100px;background: #f56c6c;color: white;" @click="cancel">清空</el-button>
      <el-button style="width: 100px;" type="primary" @click="change">确定</el-button>
    </div>
  </div>
  </div>
</template>

<style scoped>
.app-containermain{
  width: 750px;
  margin: 0 auto;
}
.fontsize{
  font-weight: 600;
  font-size: 18px;
  margin: 20px 0;
}
.flexdiv{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  letter-spacing:1px;
}
.fontw{
  width: 150px;
  margin-right: 5px;
  margin-left: 80px;
  color: red;
}

</style>
<script>
//   import { updateAdminPassword } from '@/api/admin'
import {enterpriseConfigcreate,enterpriseConfiglist,sysuserlist,sysauthinfo,enterpriseConfigupdate} from '@/api/notificationmanagement'


export default {
  name: 'ChangePassword',
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入内容'))
      } else {
        callback()
      }
    }
    return {
      fsiteNo: this.$store.state.user.fsiteNo,
      dataForm: {
        fsiteNo: '',
        addressBookAppid: '',
        addressBookSecret: '',
        selfAppAgentid: '',
        selfAppAppid: '',
        selfAppSecret: ''
      },
      rules: {
        fsiteNo: [
          { required: true, message: 'fsiteNo不能为空', trigger: 'blur' }
        ],
        addressBookAppid: [
          { required: true, message: 'addressBookAppid不能为空', trigger: 'blur' },
          { validator: validatePass, trigger: 'blur' }
        ],
        addressBookSecret: [
          { required: true, message: 'addressBookSecret不能为空', trigger: 'blur' },
          { validator: validatePass, trigger: 'blur' }
        ],
        agentid: [
          { required: true, message: 'agentid不能为空', trigger: 'blur' },
          { validator: validatePass, trigger: 'blur' }
        ],
        selfAppAppid: [
          { required: true, message: 'selfAppAppid不能为空', trigger: 'blur' },
          { validator: validatePass, trigger: 'blur' }
        ],
        selfAppSecret: [
          { required: true, message: 'selfAppSecret不能为空', trigger: 'blur' },
          { validator: validatePass, trigger: 'blur' }
        ],
      }
    }
  },
  created(){

      this.getlist(),
      this.getsysuserlist()
    },
  methods: {
    getlist(){
      var newjson = {}
      //111111
      console.log("内存数据",this.$store.state.user)
      newjson.fsiteNo = this.fsiteNo

      sysauthinfo().then(response=>{
        console.log('sysauthinfo接口',response)
        enterpriseConfiglist(newjson).then(res=>{
          let arr =res.data.data.list.filter(item=>{
            return item.fsiteNo == response.data.data.fsiteNo
          })
          console.log('res接口',res)

          this.dataForm =arr[0]
          
        })
      })


    },

    //获取微信用户数据
    getsysuserlist(){
      sysuserlist().then(res=>{
        // console.log("12345678987654321",res)
      })
    },



    //点击按钮清空内容
    cancel(){
      
      this.dataForm.fsiteNo="",
      this.dataForm.addressBookAppid=""
      this.dataForm.addressBookSecret=""
      this.dataForm.selfAppAgentid=""
      this.dataForm.selfAppAppid=""
      this.dataForm.selfAppSecret=""
      this.$message('清空成功');
      
    },

    //点击按钮确定提交内容
    change() {
      console.log("777777",this.dataForm)

      // enterpriseConfigupdate(this.dataForm).then(res=>{
      //   console.log('chenggong',res)
      //   this.dataForm=res.data.data
      // })


      if(this.dataForm.fsiteNo!="" && this.dataForm.addressBookAppid!="" && this.dataForm.addressBookSecret!=""
      && this.dataForm.selfAppAgentid!=""  && this.dataForm.selfAppAppid!="" && this.dataForm.selfAppSecret!="")
      {
        enterpriseConfigcreate(this.dataForm).then(res=>{
        console.log('chenggong',res)
        this.dataForm=res.data.data
      })

        this.$message({
        message: '数据保存成功',
        type: 'success'
      });
      }else{
        this.$message('数据不能为空');
      }
      
    }

  }
}
</script>
